<template>
  <div class="task-item" :class="'ts' + status">
    <div class="task-header">
      <span class="task-stage">{{ langName }}</span>
      <span class="task-module">{{ moduleName }}</span>
       <span class="task-level" :class="levelClass">{{ leaveName }}</span>
    </div>
    
    <div class="task-content">
      <h3 class="task-title" v-html="title"></h3>
      <div class="task-actions">
        <el-button type="primary" @click="$emit('preview:task', task)">
          <el-icon><View /></el-icon> 查看
        </el-button>
        <el-button type="warning" v-if="status === 0" @click="$emit('start-task', task)">
          <el-icon><Grid /></el-icon> 开始
        </el-button>
        <el-button type="success" @click="$emit('update:code', task)" v-if="status === 1 || status === 2">
          <el-icon><Upload /></el-icon> 提交
        </el-button>
        <el-button type="danger" v-if="status === 3 || status === 4 || status === -1" @click="$emit('update:code', task)">
          <el-icon><Edit /></el-icon> 修改
        </el-button>
        <el-button type="secondary" v-if="status === 4" @click="$emit('over-task', task)">
          <el-icon><Check /></el-icon> 完成
        </el-button>
      </div>
    </div>
  </div>
  
</template>

<script>

export default {
  props: {
    leave: {type: String, required: true},
    id: {type: Number, required: true},
    langName: {type: String, required: true},
    moduleName: {type: String, required: true},
    title: {type: String, required: true},
    status: {type: Number, required: false},
  },
  computed: {
    leaveName() {
      switch (this.leave) {
        case '简单题':
          return '简单题';
        case '中等题':
          return '中等题';
        case '困难题':
          return '困难题';
        case '选做题':
          return '选做题';
      }
    },
    levelClass() {
      return {
        'level-easy': this.leave === '简单题',
        'level-medium': this.leave === '中等题',
        'level-hard': this.leave === '困难题',
        'level-optional': this.leave === '选做题'
      }
    },
    statusLabel() {
      switch (this.status) {
        case 0:
          return '未开始';
        case 1:
          return '进行中';
        case 2:
          return '需讲解';
        case 3:
          return '已提交';
        case 4:
          return '已检查';
        case 5:
          return '已完成';
        case -1:
          return '异常题';
        default:
          return '未知状态';
      }
    }
  },
}
</script>

<style scoped>
.task-item {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
  width: 100%;
  backdrop-filter: blur(8px);
  transition: transform 0.3s, box-shadow 0.3s;
}

.task-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.task-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  padding: 10px 30px;
  border-radius: 10px;
  background: var(--el-text-color-primary);
}

.task-header > * {
  flex: 1 1 auto ;
  text-align: center;
}

.task-stage {
  font-size: 13px;
  color: #4a80ff;
  background: rgba(74, 128, 255, 0.15);
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 500;
}

.task-module {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 12px;
  border-radius: 6px;
}

.task-level {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 500;
  color: aquamarine;
  background: rgba(255, 255, 255, 0.1);
}

.level-easy {
  color: #67c23a;
  background: rgba(103, 194, 58, 0.15);
}

.level-medium {
  color: #e6a23c;
  background: rgba(230, 162, 60, 0.15);
}

.level-hard {
  color: #f56c6c;
  background: rgba(245, 108, 108, 0.15);
}

.level-optional {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
}

.task-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 50px;
  padding: 8px 0;
}

.task-title {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
  font-weight: 500;
  flex: 1;
  padding-right: 30px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.el-button {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 6px;
  transition: background 0.3s;
  margin-left: 0 !important;
}

.el-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.task-item::before {
  content: attr(data-status);
  position: absolute;
  top: 10px;
  right: 25px;
  background-color: #1E9FFF;
  color: #fff;
  padding: 5px 10px;
  font-size: 10px;
  transform: translate(50%, -50%);
  transform-origin: top right;
  z-index: 10;
  border-radius: 0px 10px 0 15px;
}

.ts0::before {
  content: '未开始';
  background-color: #393D49;
}

.ts1::before {
  content: '进行中';
  background-color: #1E9FFF;
}

.ts2::before {
  content: '需讲解';
  background-color: #FFB800;
}

.ts3::before {
  content: '已提交';
  background-color: #5FB878;
}

.ts4::before {
  content: '已检查';
  background-color: #009688;
}

.ts5::before {
  content: '已完成';
  background-color: #009688;
}

.ts-1::before {
  content: '异常题';
  background-color: #FF5722;
}


</style>